﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml.Linq;

namespace RSSReader.WebClient.Models
{
  public class FeedArticle
  {
    public string Title { get; set; }
    public string Link { get; set; }
    public string SourceLink { get; set; }
    public string Description { get; set; }
    public DateTime? PublicationDate { get; set; }
    public bool HaveBeenRed { get; set; }
    public bool IsFavorite { get; set; }
    public string SourceName { get; set; }

    public FeedArticle() { }
    public FeedArticle(XElement item)
    {
      if (item.Element("title") != null)
      {
        Title = item.Element("title").Value;
        if (Title.Length > 120)
          Title = Title.Substring(0, 120) + "...";
      }
      if (item.Element("link") != null)
        Link = item.Element("link").Value;
      if (item.Element("description") != null)
        Description = item.Element("description").Value;
      if (item.Element("pubDate") != null)
        PublicationDate = new DateTime?(Convert.ToDateTime(item.Element("pubDate").Value));
    }
  }
}